#include <QApplication>
#include <QSqlQuery>
#include "mainwindow.h"
#include "login.h"
#include <QTextCodec>
#include <QTranslator>
#include <QDesktopWidget>

bool CreateConnection()
{
    QSqlDatabase db;
    db = QSqlDatabase::addDatabase("QSQLITE");
    db.setDatabaseName("./../CashRegisterSystem/DataBase/SupermarketCashRegisterSystem.db");
    if(!db.open()){
        qCritical("Can't open database: %s(%s)",
                  db.lastError().text().toLocal8Bit().data(),
                  qt_error_string().toLocal8Bit().data());

        return false;
    }
    return true;
}

void CloseConnection()
{
    QSqlDatabase::database().close();
}

//测试git的使用
//第二次提交
//第三次提交
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    if(!CreateConnection())
        return 1;

    QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));

    Login L;
    L.move((QApplication::desktop()->width() - L.width())/2,
                     (QApplication::desktop()->height() - L.height())/2);
    L.setWindowFlags(Qt::SplashScreen | Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint);
    L.show();

    int res = a.exec();

    CloseConnection();

    return res;
}
